Error when using dplyr {{ }} with aggregate inside a function